package com.wn.web;

import com.wn.annotation.RequireRoles;
import com.wn.auth.JWTUtil;
import com.wn.common.Const;
import com.wn.common.PageParam;
import com.wn.ov.*;
import com.wn.pojo.*;
import com.wn.resopnse.ServerResponse;
import com.wn.service.DraRecordService;
import com.wn.service.NurseRecordService;
import com.wn.service.NurseService;
import com.wn.service.RoomService;
import com.wn.service.doctorService.MedicalAdviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @BelongsProject: his
 * @BelongsPackage: com.wn.web
 * @Author: 皓芷
 * @CreateTime: 2020-10-23 16:05
 * @Description:
 */
@Api(value = " 护士站管理裂口",description=" 护士站管理接口")
@RestController
@RequestMapping("nurse")
public class NurseController {

    @Autowired
    private RoomService roomService;

    @Autowired
    private NurseRecordService nurseRecordService;

    @Autowired
    private NurseService nurseService;

    @Autowired
    private MedicalAdviceService medicalAdviceService;

    @Autowired
    private DraRecordService draRecordService;

    /**
     * 入院登记(添加患者详情)
     * @param hospitalizedApplication
     * @return
     */
    @PostMapping("add-patientDetail")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("入院登记(通过审核并生成患者详情)")
    public ServerResponse addPatientDetail(@RequestHeader("token")String token,@RequestBody HospitalizedApplication hospitalizedApplication){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        return nurseService.addPatientDetail(hospitalizedApplication,user.getId());
    }

    /** 查询所有的出入院申请单 */
    @PostMapping("get-listInHospital")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("查询所有的入院申请单")
    public ServerResponse getListInHospital(@RequestHeader("token")String token,@RequestBody PageParam<HospitalizedApplication> pageParam){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        System.out.println(user.getId());
        return nurseService.getListInHospital(pageParam);
    }

    /** 获取所有床位列表 */
    @PostMapping("get-roomList")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("获取所有床位列表")
    public ServerResponse getRoomList(@RequestHeader("token")String token,@RequestBody PageParam<RoomOv> pageParam){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        return roomService.getRoomList(pageParam);
    }

    /** 获取护士列表 */
    @PostMapping("get-nurseList")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("获取护士列表")
    public ServerResponse getNurseList(@RequestHeader("token")String token){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        return nurseService.getNurseList();
    }

    /** 为入院的患者分配护士与床位 */
    @PostMapping("update-inHospitalForm")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("入院的患者分配护士与床位")
    public ServerResponse giveBedAndNurse(@RequestHeader("token")String token,@RequestBody PatientDetail patientDetail){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        return nurseService.giveBedAndNurse(patientDetail,user.getId());
    }

    /**
     * 通过护士id获取护理列表
     * @param pageParam
     * @return
     */
    @PostMapping("get-NursingRecordList")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("通过护士id获取护理列表")
    public ServerResponse getNursingListByDoctorId(@RequestHeader("token")String token,@RequestBody PageParam<NurseRecord> pageParam){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        pageParam.getModel().setId(user.getId());
        return nurseRecordService.getNursingListByDoctorId(pageParam);
    }

    /** 通过护士id查询其住院患者详情列表 */
    @GetMapping("get-patientList")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("通过护士id查询患者详情列表")
    public ServerResponse getPatientList(Integer id){
        return nurseService.getPatientList(id);
    }

    /**
     * 添加护理记录
     * @param nurseRecordAndCostDrugOv
     * @return
     */
    @PostMapping("add-nursingRecord")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("添加护理记录")
    public ServerResponse addNursingRecord(@RequestHeader("token")String token, @RequestBody @Validated NurseRecordAndCostDrugOv nurseRecordAndCostDrugOv){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        return nurseRecordService.addNursingRecord(nurseRecordAndCostDrugOv,user.getId());
    }

    /**
     * 删除护理记录
     * @param nurseRecord
     * @return
     */
    @DeleteMapping("delete-nursingRecord")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("删除护理记录")
    public ServerResponse deleteNursingRecord(@RequestHeader("token")String token,@RequestBody NurseRecord nurseRecord) {
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        return nurseRecordService.deleteNursingRecord(nurseRecord.getId());
    }

    //查询在院或出院病人详情
    @PostMapping("query-patientList")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("查询在院或出院病人详情")
    public ServerResponse queryPatientByStatus(@RequestHeader("token")String token,@RequestBody PageParam<PatientOv> pageParam){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        System.out.println(pageParam.getModel());
        return nurseService.queryPatientByStatus(pageParam);
    }

    //查询药品列表（不分页）
    @PostMapping("query-drugList")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("查询药品列表")
    public ServerResponse getDrugList(@RequestHeader("token")String token){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        return draRecordService.getDrugList();
    }

    //获取某患者的所有医嘱
    @PostMapping("get-medicalAdvice")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("获取某患者的所有医嘱")
    public ServerResponse getMedicalAdviceByPatientId(@RequestHeader("token")String token,@RequestBody PageParam<PatientDetail> pageParam){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        return nurseService.getMedicalAdviceByPatientId(pageParam);
    }

    //执行患者医嘱
    @PostMapping("do-medicalAdvice")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("执行患者医嘱")
    public ServerResponse updateMedicalAdvice(@RequestHeader("token")String token,@RequestBody MedicalAdvice medicalAdvice){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        return medicalAdviceService.doMedicalAdvice(medicalAdvice.getId(),user.getId());
    }

    //出院审核
    @PostMapping("out-hospital")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("出院审核")
    public ServerResponse updateOutHospitalStatus(@RequestHeader("token")String token,@RequestBody HospitalizedApplication hospitalizedApplication){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        return nurseService.updateOutHospitalStatus(hospitalizedApplication,user.getId());
    }

    //驳回出入院请求
    @PostMapping("rollback-theReq")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("驳回出入院请求")
    public ServerResponse rollbackReq(@RequestHeader("token")String token,@RequestBody HospitalizedApplication hospitalizedApplication){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        return nurseService.rollbackReq(hospitalizedApplication);
    }

    //根据病床id查询该病床的病人详细资料
    @PostMapping("look-patientByRoomId")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("根据病床id查询该病床的病人详细资料")
    public ServerResponse lookPatientByRoomId(@RequestHeader("token")String token,@RequestBody Room room){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        return nurseService.lookPatientByRoomId(room.getId());
    }

    //获取待床患者列表
    @PostMapping("get-noBedPatientList")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("获取待床患者列表")
    public ServerResponse getNoBedPatientList(@RequestHeader("token")String token){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        return nurseService.getNoBedPatientList();
    }

    //查询患者的总费用
    @PostMapping("get-allCost")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("查询患者的总费用")
    public ServerResponse getAllCost(@RequestHeader("token")String token,@RequestBody Cost cost){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        return nurseService.getAllCost(cost.getId());
    }

    //添加申请转科记录
    @PostMapping("add-departmentRecord")
    @RequireRoles(roles = "main_nurse")
    @ApiOperation("添加申请转科记录")
    public ServerResponse addDepartmentRecord(@RequestHeader("token")String token,@RequestBody DepartmentCode departmentCode){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        departmentCode.setApplicant(user.getId());
        departmentCode.setCreateUserId(user.getId());
        departmentCode.setId(null);
        System.out.println(departmentCode);
        return nurseService.addDepartmentRecord(departmentCode);
    }

    //查看转科记录(通过患者id)
    @PostMapping("get-departmentRecord")
    @RequireRoles(roles = "main_nurse,doctor,main_doctor")
    @ApiOperation("查看转科记录(通过患者id)")
    public ServerResponse getDepartmentRecord(@RequestHeader("token")String token,@RequestBody PageParam<DepartmentRecordOv> pageParam){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        return nurseService.getDepartmentRecord(pageParam);
    }

    //获取科室分类（分页）
    @PostMapping("get-departmentList")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("获取科室分类（分页）")
    public ServerResponse getDepartmentList(@RequestHeader("token")String token,@RequestBody PageParam<Department> pageParam){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        return nurseService.getDepartmentList(pageParam);
    }

    //获取病房列表（不分页）
    @PostMapping("get-RoomListByBox")
    @RequireRoles(roles = "nurse,main_nurse")
    @ApiOperation("获取病房列表（不分页）")
    public ServerResponse getRoomListByBox(@RequestHeader("token")String token,@RequestBody Room room){
        UserOv user = JWTUtil.parserToken(token, Const.PUBLIC_KEY);
        return nurseService.getRoomListByBox(room.getId());
    }

}
